package com.sojson.aspect;

import org.aspectj.lang.annotation.Pointcut;

import com.sojson.constant.ConstantServlet;

/**
 * 基础切点类
 * 
 * @author liu
 * @date 2021-07-04
 */
public interface PointcutsBase {

    /** Mapping注解的包路径 */
    String ANNO_MAPPING = "org.springframework.web.bind.annotation";
    /** Controller下所有方法织入点 */
    String POINT_CONTROLLER =
        "execution(* " + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER_ALL + "..*.*(..)) || " + "execution(* "
            + ConstantServlet.PACKAGE_DEFAULT_BASE + "..*." + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER + "..*.*(..))";
    /** Service下所有方法织入点 */
    String POINT_SERVICE =
        "execution(* " + ConstantServlet.PACKAGE_DEFAULT_SERVICE_ALL + "..*.*(..)) || " + "execution(* "
            + ConstantServlet.PACKAGE_DEFAULT_BASE + "..*." + ConstantServlet.PACKAGE_DEFAULT_SERVICE + "..*.*(..))";

    // =======================================================================================================
    // =======================================================================================================
    // =======================================================================================================

    /** Controller下所有方法织入点 */
    @Pointcut(POINT_CONTROLLER)
    default void controller() {}

    /** Service下所有方法织入点 */
    @Pointcut(POINT_SERVICE)
    default void service() {}

    /** 所有get方法织入点 */
    @Pointcut("execution(* " + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER_ALL + "..*.get*(..)) || " + "execution(* "
        + ConstantServlet.PACKAGE_DEFAULT_BASE + "..*." + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER + "..*.get*(..))")
    default void gets() {}

    /** 所有find方法织入点 */
    @Pointcut("execution(* " + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER_ALL + "..*.find*(..)) || " + "execution(* "
        + ConstantServlet.PACKAGE_DEFAULT_BASE + "..*." + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER + "..*.find*(..))")
    default void find() {}

    /** 所有query方法织入点 */
    @Pointcut("execution(* " + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER_ALL + "..*.query*(..)) || " + "execution(* "
        + ConstantServlet.PACKAGE_DEFAULT_BASE + "..*." + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER
        + "..*.query*(..))")
    default void query() {}

    /** 所有select方法织入点 */
    @Pointcut("execution(* " + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER_ALL + "..*.select*(..)) || " + "execution(* "
        + ConstantServlet.PACKAGE_DEFAULT_BASE + "..*." + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER
        + "..*.select*(..))")
    default void select() {}

    /** 所有count方法织入点 */
    @Pointcut("execution(* " + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER_ALL + "..*.count*(..)) || " + "execution(* "
        + ConstantServlet.PACKAGE_DEFAULT_BASE + "..*." + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER
        + "..*.count*(..))")
    default void count() {}

    /** 所有list方法织入点 */
    @Pointcut("execution(* " + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER_ALL + "..*.list*(..)) || " + "execution(* "
        + ConstantServlet.PACKAGE_DEFAULT_BASE + "..*." + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER + "..*.list*(..))")
    default void list() {}

    /** 所有list方法织入点 */
    @Pointcut("execution(* " + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER_ALL + "..*.page*(..)) || " + "execution(* "
        + ConstantServlet.PACKAGE_DEFAULT_BASE + "..*." + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER + "..*.page*(..))")
    default void page() {}

    /** 不包含获取验证码织入点 */
    @Pointcut("!execution(* " + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER_ALL + "..*.getVerifyCode*(..)) && "
        + "!execution(* " + ConstantServlet.PACKAGE_DEFAULT_BASE + "..*." + ConstantServlet.PACKAGE_DEFAULT_CONTROLLER
        + "..*.getVerifyCode*(..))")
    default void noVerifyCode() {}

    /** 不包含获取验证码织入点 */
    @Pointcut("gets() && noVerifyCode()")
    default void getNoVerifyCode() {}

    /** 所有@RequestMapping注解的方法 */
    @Pointcut("@annotation(" + ANNO_MAPPING + ".RequestMapping)")
    default void requestMapping() {}

    /** 所有@GetMapping注解的方法 */
    @Pointcut("@annotation(" + ANNO_MAPPING + ".GetMapping)")
    default void getMapping() {}

    /** 所有@PostMapping注解的方法 */
    @Pointcut("@annotation(" + ANNO_MAPPING + ".PostMapping)")
    default void postMapping() {}

    /** 所有@PutMapping注解的方法 */
    @Pointcut("@annotation(" + ANNO_MAPPING + ".PutMapping)")
    default void putMapping() {}

    /** 所有@DeleteMapping注解的方法 */
    @Pointcut("@annotation(" + ANNO_MAPPING + ".DeleteMapping)")
    default void deleteMapping() {}

    @Pointcut("@annotation(" + ConstantServlet.PACKAGE_DEFAULT_ANNOTATION_ALL + ".ReCommit)" + "|| @within("
        + ConstantServlet.PACKAGE_DEFAULT_ANNOTATION_ALL + ".ReCommit)")
    default void reCommit() {}

    // =======================================================================================================
    // =======================================================================================================
    // =======================================================================================================

    /** Controller下所有方法切点 */
    String POINTCUT_CONTROLLER = "controller()";

    /** 获取数据切点 */
    String POINTCUT_GET =
        //
        "find()"
            //
            + "||getNoVerifyCode()"
            //
            + "||query()"
            //
            + "||select()"
            //
            + "||count()"
            //
            + "||list()"
            //
            + "||page()"
    //
    ;

    /** 自定义的除获取外的控制器 */
    String POINTCUT_MAPPING_REQUEST =
        //
        "getMapping()"
            //
            + "postMapping()"
            //
            + "||putMapping()"
            //
            + "||deleteMapping()"
    //
    ;

    /** 自定义的除获取外的控制器 */
    String POINTCUT_MAPPING_GET_NO =
        //
        "postMapping()"
            //
            + "||putMapping()"
            //
            + "||deleteMapping()"
    //
    ;

    /** 所有需要放置重复提交的控制器 */
    String POINTCUT_RE_COMMIT =
        //
        "postMapping()"
            //
            + "||putMapping()"
            //
            + "||deleteMapping()"
            //
            + "||reCommit()"
    //
    ;

}